package com.spa.infrastructure.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spa.application.command.admin.TicketAddCommand;
import com.spa.application.command.admin.TicketEditCommand;
import com.spa.application.dto.PageResult;
import com.spa.application.dto.admin.TicketDTO;
import com.spa.application.dto.admin.TicketExportDTO;
import com.spa.application.dto.admin.TicketPickRecordDTO;
import com.spa.application.dto.admin.TicketPickRecordExportDTO;
import com.spa.application.dto.member.MemberTicketDTO;
import com.spa.domain.entity.Ticket;
import com.spa.infrastructure.enums.dict.coupon.CouponComeIntoForceTypeEnum;
import com.spa.infrastructure.enums.dict.coupon.CouponDiscountTypeEnum;
import com.spa.infrastructure.enums.dict.coupon.CouponTypeEnum;
import com.spa.infrastructure.repository.po.TicketPO;
import com.spa.infrastructure.repository.po.UserTicketRefPO;
import jdk.jfr.Name;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
@MapperConfig(unmappedTargetPolicy = ReportingPolicy.WARN)
public interface TicketMapperStruct {

    TicketMapperStruct INSTANCE = Mappers.getMapper(TicketMapperStruct.class);

    TicketPO command2Po(TicketAddCommand command);
    TicketPO command2Po(TicketEditCommand command);
    Page<Ticket> po2Entity4Page(Page<TicketPO> poPage);
    PageResult<TicketDTO> entity2Dto4Page(Page<Ticket> page);
    PageResult<TicketPickRecordDTO> po2Dto4Page(Page<UserTicketRefPO> page);

    @Mapping(source = "discountType", target = "discountType", qualifiedByName = "int2DiscountTypeEnum")
    @Mapping(source = "comeIntoForceType", target = "comeIntoForceType", qualifiedByName = "int2ComeIntoForceTypeEnum")
    @Mapping(source = "type", target = "type", qualifiedByName = "int2CouponTypeEnum")
    TicketPickRecordDTO po2Dto(UserTicketRefPO po);
    List<Ticket> po2Entity4List(List<TicketPO> poList);

    Ticket po2Entity(TicketPO po);
    PageResult<MemberTicketDTO> entity2MemberDto4Page(Page<Ticket> page);

    List<MemberTicketDTO> entity2MemberDto4List(List<Ticket> page);
    MemberTicketDTO entityMember2Dto(Ticket entity);


    @Named("int2DiscountTypeEnum")
    default CouponDiscountTypeEnum int2DiscountTypeEnum(int status) {
        return CouponDiscountTypeEnum.byCode(status);
    }

    @Named("int2ComeIntoForceTypeEnum")
    default CouponComeIntoForceTypeEnum int2ComeIntoForceTypeEnum(int status) {
        return CouponComeIntoForceTypeEnum.byCode(status);
    }

    @Named("int2CouponTypeEnum")
    default CouponTypeEnum int2CouponTypeEnum(int status) {
        return CouponTypeEnum.byCode(status);
    }

    @Named("intDiscountType2Str")
    default String intDiscountType2Str(int type) {
        return CouponDiscountTypeEnum.byCode(type).getDesc();
    }

    @Named("intForceType2Str")
    default String intForceType2Str(int type) {
        return CouponComeIntoForceTypeEnum.byCode(type).getDesc();
    }

    @Named("intType2Str")
    default String intType2Str(int type) {
        return CouponTypeEnum.byCode(type).getDesc();
    }

    List<TicketExportDTO> entity2ExportDTO(List<Ticket> list);

    @Mapping(source = "discountType", target = "discountType", qualifiedByName = "intDiscountType2Str")
    @Mapping(source = "comeIntoForceType", target = "comeIntoForceType", qualifiedByName = "intForceType2Str")
    @Mapping(source = "type", target = "type", qualifiedByName = "intType2Str")
    TicketExportDTO entity2ExportDTO(Ticket entity);

    List<TicketPickRecordExportDTO> po2ExportDTO(List<UserTicketRefPO> list);

    @Mapping(source = "discountType", target = "discountType", qualifiedByName = "intDiscountType2Str")
    @Mapping(source = "comeIntoForceType", target = "comeIntoForceType", qualifiedByName = "intForceType2Str")
    @Mapping(source = "type", target = "type", qualifiedByName = "intType2Str")
    TicketPickRecordExportDTO po2ExportDTO(UserTicketRefPO po);

}
